package cn.bgs.controller;


import cn.bgs.common.R;
import cn.bgs.pojo.Announcement;
import cn.bgs.service.IAnnouncementService;
import cn.bgs.utils.RedisUtil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 公式公告表(社区活动表) 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/announcement")
public class AnnouncementController {

    @Autowired
    private IAnnouncementService announcentService;

    @Autowired
    private RedisUtil redisUtil;

    /**
     * 获取所有公告
     * @return
     */
    @GetMapping("/getAnnouncement")
    public R getAnnouncement(Integer id){
       List<Announcement>  noticelist= (List<Announcement>) redisUtil.get("Notice");
       if (noticelist==null){
           List<Announcement> list=announcentService.getAnnouncement(id);
           redisUtil.set("Notice",list);
           redisUtil.expire("Notice",60*60);
           return  R.ok().data("list",list);
       }
        return R.ok().data("list",noticelist);
    }

//    Boolean deleteById(Integer id);
//
//    Boolean updateById(Integer id,String huod, String textarea, String marketName);
    @RequestMapping("findAll")
    private List<Announcement> findAll(@Param("id") Integer id,@Param("biaoti") String biaoti,@Param("lei") String lei){
        return announcentService.findAll(id,biaoti,lei);
    }
    @RequestMapping("delete")
    private Boolean deleteById(Integer id){
        return announcentService.deleteById(id);
    }
    @RequestMapping("update")
    private Boolean updateById(@Param("id") Integer id,@Param("huod") String huod,@Param("textarea") String textarea,@Param("marketName") String marketName,@Param("qu") Integer qu){
        return announcentService.updateById(id,huod,textarea,marketName,qu);
    }
}
